import {getDetail} from 'http'
const OK =200
export default {
    state:{
        goodsDetail:{}
    },
    getters:{},
    mutations:{
        getDetail(state,goodsDetail){
            state.goodsDetail = goodsDetail
        },
        choosed(state,{attrIndex,valIndex}){
            //找到点击的属性,将其所有isChecked 置为0
            state.goodsDetail.spuSaleAttrList.forEach((item,index) => {
                if(index === attrIndex){
                    item.spuSaleAttrValueList.forEach(val => {
                        val.isChecked = '0'
                    })
                }
            });
            state.goodsDetail.spuSaleAttrList[attrIndex].spuSaleAttrValueList[valIndex].isChecked = '1'
        }
    },
    actions:{
        async getDetail({commit},id){
            const {code,data} = await getDetail(id)
            if(code === OK){
                commit('getDetail',data)
            }
        },
        async choosed({commit},{attrIndex,valIndex}){
            commit('choosed',{attrIndex,valIndex})
        }
    }
}